package org.htp.freemarkerfornetbeans.lexer;

import org.netbeans.spi.lexer.Lexer;
import org.netbeans.spi.lexer.LexerRestartInfo;

/**
 *
 * @author Artem Pleskatsevich
 */
public class FreeMarkerLexer implements Lexer<FreeMarkerTokenId> {

    private LexerRestartInfo<FreeMarkerTokenId> info;
    private FMParserTokenManager fMParserTokenManager;

    FreeMarkerLexer(final LexerRestartInfo<FreeMarkerTokenId> info) {
        this.info = info;
        SimpleCharStream simpleCharStream = new SimpleCharStream(info.input());
        fMParserTokenManager = new FMParserTokenManager(simpleCharStream);
    }

    public org.netbeans.api.lexer.Token<FreeMarkerTokenId> nextToken() {
         Token token = null;
        try {
            token = fMParserTokenManager.getNextToken();
        } catch (TokenMgrError e) {
            return info.tokenFactory ().createToken (FreeMarkerLanguageHierarchy.getToken (FMParserConstants.EOF));
        }
        if (info.input ().readLength () < 1) return null;
        return info.tokenFactory ().createToken (FreeMarkerLanguageHierarchy.getToken (token.kind));
    }

    public Object state() {
        return null;
    }

    public void release() {
    }
}
